function HashTable() {
    this.table = new Array(137);
    for (let i = 0; i < this.table.length; i++) {
        this.table[i] = [];
    }
    this.hash = hash;
    this.showDistro = showDistro;
    this.put = put;
    this.get = get;
}

const hash = function (key) {
    const H = 37;
    if (typeof (key) === "number") {
        return key % this.table.length;
    }
    else if (typeof (key) === "string") {
        let charCodeSum = 0;
        for (let i = 0; i < key.length; i++) {
            charCodeSum += H * charCodeSum + key.charCodeAt(i);
        }
        return charCodeSum % this.table.length;
    }
    return null;
}

const put = function (key, value) {
    const hashNumber = this.hash(key);
    if (hashNumber !== null) {
        const currentTableItem = this.table[hashNumber];
        currentTableItem.push(key);
        currentTableItem.push(value);
    }
}

const get = function (key) {
    const hashNumber = this.hash(key);
    if (hashNumber !== null) {
        const currentTableItem = this.table[hashNumber];
        let i = 0;
        while (currentTableItem[i] !== key) {
            i = i + 2;
        }
        return currentTableItem[i + 1];
    }
    else {
        return null;
    }
}

const showDistro = function () {
    let stringLine = "";
    this.table.forEach((tableItem) => {
        if (tableItem.length > 0) {
            let i = 0;
            while (tableItem[i] !== undefined) {
                stringLine += tableItem[i] + ": " + tableItem[i + 1] + "=>"
                i = i + 2;
            }
        }
    })
    console.log(stringLine);
}

const hashTable = new HashTable();
hashTable.put("asf", "test1");
hashTable.put("asf", "test2");
hashTable.put("asf", "test3");
hashTable.showDistro();